import { Controller } from "../../mvc/core/Controller";
import { IOpenRechargeController } from "./interfaces/IOpenRechargeController";
import { OpenRechargeIcon } from "../view/openRecharge/OpenRechargeIcon";
import { EActiveType } from "../../../Message/Public/EActiveType";
import { IView } from "../../mvc/interfaces/IView";
import { OpenRechargeModule } from "../../../modules/OpenRechargeModule";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
import { ServerCommand } from "../mvc/ServerCommand";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SOpenRechargeInfoEx } from "../../../Message/Public/SOpenRechargeInfoEx";
import { OpenRechargeDataUtil } from "../view/openRecharge/OpenRechargeDataUtil";
import { SActiveToClient } from "../../../Message/Public/SActiveToClient";
import { ClockManager } from "../manager/ClockManager";
import { DataEvent } from "../events/DataEvent";
import { GameProxy } from "../mvc/GameProxy";
type int = number;
//class OpenRechargeController
    
    export  class OpenRechargeController extends Controller implements IOpenRechargeController
    {
       

        public get openRechargeIcon(): OpenRechargeIcon
        {
            if (this._openRechargeIcon == null) 
            {
                this._openRechargeIcon = new OpenRechargeIcon();
                this._openRechargeIcon.addEventListener(flash.events.MouseEvent.CLICK, this.onOpenRechargeIconClickHandler);
            }
            return this._openRechargeIcon;
        }

        /* internal  */onOpenRechargeIconClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            view.show();
            this._openRechargeModule.updateGiftBagInfo(EActiveType._EActiveTypeRechargeGiftBagEx);
            this._openRechargeModule.updateResTime();
            return;
        }

        protected /* override */ initView(): IView
        {
            if (this._openRechargeModule == null) 
            {
                this._openRechargeModule = new OpenRechargeModule();
            }
            return this._openRechargeModule;
        }

        protected /* override */ initServer(): void
        {
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicOpenRechargeInfoEx, this.onOpenRechargeInfoExHandler);
            NetDispatcher.addCmdListener(ServerCommand.ActiveTypeRechargeGiftBagEx, this.onRechargeGiftBagExActiveHandler);
            Dispatcher.addEventListener(EventName.OpenRechargeGetGiftBag, this.onOpenRechargeGetGiftBagHandler);
            Dispatcher.addEventListener(EventName.OpenRechargeGetGiftBagSuccess, this.onOpenRechargeGetGiftBagSuccessHandler);
            return;
        }

        /* internal  */onOpenRechargeInfoExHandler(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SOpenRechargeInfoEx;
            OpenRechargeDataUtil.instance.openRechargeInfoEx = loc1;
            if (this._openRechargeModule && !this._openRechargeModule.isHide) 
            {
                this._openRechargeModule.updateGiftBagInfo(EActiveType._EActiveTypeRechargeGiftBagEx);
            }
            return;
        }

        /* internal  */onRechargeGiftBagExActiveHandler(arg1: SActiveToClient): void
        {
            this._activeToClient = arg1;
            var loc1=cache.active.isActiveInEffect(arg1.code);
            if (loc1 && this.openRechargeIcon.isHide) 
            {
                ClockManager.instance.addDateCall(arg1.endDt, this.removeOpenRechargeActive);
                this.openRechargeIcon.show();
            }
            return;
        }

        /* internal  */removeOpenRechargeActive(): void
        {
            if (this._openRechargeIcon && !this._openRechargeIcon.isHide) 
            {
                this.openRechargeIcon.hide();
            }
            if (this._openRechargeModule && !this._openRechargeModule.isHide) 
            {
                this._openRechargeModule.hide();
            }
            if (this._activeToClient) 
            {
                ClockManager.instance.removeDateCall(this._activeToClient.endDt);
            }
            return;
        }

        /* internal  */onOpenRechargeGetGiftBagHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            GameProxy.roleProxy.getOpenRechargeGiftBagEx(loc1);
            return;
        }

        /* internal  */onOpenRechargeGetGiftBagSuccessHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as Array<any>;
            OpenRechargeDataUtil.instance.hadGetCodes = loc1;
            if (this._openRechargeModule && !this._openRechargeModule.isHide) 
            {
                this._openRechargeModule.updateGiftBagInfo(EActiveType._EActiveTypeRechargeGiftBagEx);
            }
            return;
        }

        private /* var */_openRechargeIcon: OpenRechargeIcon;

        private /* var */_openRechargeModule: OpenRechargeModule;

        private /* var */_activeToClient: SActiveToClient;
    }
